﻿using Hidistro.Membership.Core.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Hidistro.UI.SaleSystem.Tags
{
    public class wnxd_User_Gender : WebControl
    {
        protected override void OnInit(EventArgs e)
        {
            int g;
            int.TryParse(this.Page.Request.Form[this.ID], out g);
            this.Gender = (Gender)Enum.ToObject(typeof(Gender), g);
        }
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(this.html());
        }
        private string html()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<a class=\"{0}{1}\" href=\"javascript:void(0);\" v=\"{2}\"><em class=\"gg\"></em><i>男</i></a>", this.ID, this.Gender == Gender.Male ? " tt" : "", (int)Gender.Male);
            sb.AppendFormat("<a class=\"{0}{1}\" href=\"javascript:void(0);\" v=\"{2}\"><em class=\"gg\"></em><i>女</i></a>", this.ID, this.Gender == Gender.Female ? " tt" : "", (int)Gender.Female);
            sb.AppendFormat("<a class=\"{0}{1}\" href=\"javascript:void(0);\" v=\"{2}\"><em class=\"gg\"></em><i>保密</i></a>", this.ID, this.Gender == Gender.NotSet ? " tt" : "", (int)Gender.NotSet);
            sb.AppendFormat("<input type=\"hidden\" name=\"{0}\" value=\"{1}\" />", this.ID, (int)this.Gender);
            sb.Append("<script type=\"text/javascript\">(function(){var list=document.getElementsByClassName(\"" + this.ID + "\"),hidden=document.getElementsByName(\"" + this.ID + "\")[0],now;for(var i=0;i<list.length;i++){if(list[i].className.indexOf(\"tt\")!=-1){now=list[i]}list[i].onclick=function(){if(now!=this){now.className=now.className.replace(\" tt\",\"\");now=this;now.className+=\" tt\";hidden.value=now.getAttribute(\"v\");}}}})();</script>");
            return sb.ToString();
        }
        public Gender Gender { get; set; }
    }
}
